import time
import threading#线程
#练习生：跳舞，唱歌，打篮球

def singing():
    print("singing线程:",threading.current_thread())
    for i in range(10):
        print("正在唱歌...",i)
        time.sleep(0.5)
def dancing():
    print("dancing线程:",threading.current_thread())
    for i in range(10):
        print("正在跳舞...",i)
        time.sleep(0.5)
def playing_basketball():
    print("playing_basketball线程:",threading.current_thread())
    for i in range(10):
        print("正在打篮球...",i)
        time.sleep(0.5)
        
#必须所有的子线程都设置为守护线程池，才能一起退出,否则守护线程失去作用
if __name__ == "__main__":
    print("主线程:",threading.current_thread())
    t1 = threading.Thread(target=singing)
    #将子线程设置为守护线程，（必须在start()之前）
    t1.daemon = True
    #启动线程一
    t1.start()
    t2 = threading.Thread(target=dancing)
    #将子线程设置为守护线程（必须在start之前）
    t2.daemon = True
    #启动线程二
    t2.start()
    t3 = threading.Thread(target=playing_basketball)
    t3.daemon = True
    #启动线程三
    t3.start()
    time.sleep(2)
    
    #退出主线程
    print("主线程结束,退出")
    exit(-123)
    print("----------------------------------------")
    